#ifndef _CROSSENGINE_REALTIMER_H_
#define _CROSSENGINE_REALTIMER_H_

#include "common.h"
#include "memalloc.h"

namespace Cross
{

class SearchTree;

typedef void (*RealTimerFunction)(const DateTime&);

class IRealTimerFunctor
{
public:
    virtual ~IRealTimerFunctor(){}
    virtual void Invoke(const DateTime& now)=0;
    DEFINE_OWN_MEM_OPERATION
};

class RealTimer
{
public:
    ~RealTimer();
    explicit RealTimer(const DateTime& now);
    void Tick(const DateTime& now);
    void RegisterEveryHour(const DateTime& dateTime,IRealTimerFunctor* func);
    void RegisterEveryDay(const DateTime& dateTime,IRealTimerFunctor* func);
    void RegisterEveryMonth(const DateTime& dateTime,IRealTimerFunctor* func);
    void RegisterEveryYear(const DateTime& dateTime,IRealTimerFunctor* func);
    void RegisterEveryWeek(const DateTime& dateTime,IRealTimerFunctor* func);
private:
    void TickEveryMinute(const DateTime& now);
    SearchTree* _funcTree;
    DateTime _lastDateTime;
};

}
#endif//_CROSSENGINE_REALTIMER_H_
